<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
	<a-row>

	<a-col :span="12">
    <a-form-item label="公司抬头" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['companyType', validatorRules.companyType]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = SEAL_COM_TYPE" placeholder="请选择公司抬头"/>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="用印类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['sealFileType', validatorRules.sealFileType]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = SEAL_FILE_TYPE" placeholder="请选择用印文件类别"/>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="印章类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['sealType', validatorRules.sealType]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = SEAL_TYPE" placeholder="请选择印章类型"/>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="文件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fileName', validatorRules.fileName]" placeholder="请输入用印文件名称"></a-input>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="文件份数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fileNum', validatorRules.fileNum]" placeholder="请输入文件份数"></a-input>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="付款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['totalAmount', validatorRules.totalAmount]" placeholder="请输入付款金额" style="width: 100%"/>
        </a-form-item>
	</a-col>
	<a-col :span="24">
    <a-form-item label="备注"  :labelCol="{ xs: { span: 24 }, sm: { span: 2 }}"
                 :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 }}">
          <a-textarea v-decorator="['description']" rows="4" placeholder="请输入备注"/>
        </a-form-item>
	</a-col>
	<a-col :span="12">
    <a-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['uploadPath', validatorRules.uploadPath]" :trigger-change="true"></j-upload>
        </a-form-item>
	</a-col>

 </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "ClmCommonlySealModal",
    components: { 
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          companyType: {
            rules: [
              { required: true, message: '请输入公司抬头!'},
            ]
          },
          sealFileType: {
            rules: [
              { required: true, message: '请输入用印文件类别!'},
            ]
          },
          sealType: {
            rules: [
              { required: true, message: '请输入印章类型!'},
            ]
          },
          fileName: {
            rules: [
              { required: true, message: '请输入用印文件名称!'},
            ]
          },
          fileNum: {
            rules: [
              { required: true, message: '请输入文件份数!'},
              { pattern: /^-?\d+$/, message: '请输入整数!'},
            ]
          },
          totalAmount: {
            rules: [
              { required: true, message: '请输入付款金额!'},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
            ]
          },
          uploadPath: {
            rules: [
              { required: true, message: '请输入附件!'},
            ]
          },
        },
        url: {
          add: "/online/api/createClmCommonlySeal",
          edit: "/online/api/updateClmCommonlySeal",
          get: "/online/api/getClmCommonlySeal",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
		this.visible = true;
		this.model = {};
        if(record.id){
	      httpAction(this.url.get,{id:record.id},"post").then((res)=>{
	         if(res.success){
		        this.model = Object.assign({}, res.result);
		        this.$nextTick(() => {
		           this.form.setFieldsValue(pick(this.model,'departmentId','companyType','sealFileType','sealType','fileName','fileNum','totalAmount','description','uploadPath','statusId'))
		        })   
	         }
	      })
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            if(!formData.statusId)formData.statusId = "0";
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success('提交成功!');
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'departmentId','companyType','sealFileType','sealType','fileName','fileNum','totalAmount','description','uploadPath','statusId'))
      },

      
    }
  }
</script>
